
<template>
  <el-collapse-item :name="data.name" class="filteredit_collapse-item">
    <template #title>
      <div class="filter_collapse_checked" @click.stop>
        <el-checkbox v-model="data.enable.choose" :true-value="`true`" :false-value="`false`" />
      </div>
      <div style="font-weight: 600; font-size: 14px">{{ data.name_ch }}</div>
    </template>
    <template #icon="{ isActive }">
      <span class="icon-ele">
        <img v-if="isActive" style="width: 24px; height: 24px" src="@/assets/filter/shouqi-gray.png" alt="" />
        <img v-else style="width: 24px; height: 24px" src="@/assets/filter/zhankai-gray.png" alt="" />
      </span>
    </template>
    <div class="filteredit_collapse-item_content">
      <div class="collapse_list" v-for="(item, index) in data.option_list" :key="index"
        :style="collapselistStyle(index, data.option_list)">
        <template v-for="(item2, index2) in item" :key="`${item2.value}-${index2}`">
          <el-select v-model="item2.choose" v-if="item2.type == 'select_list'" @change="changechoose(item2)"
            :placeholder="item2.label" style="width: 120px;height: 28px; margin-bottom: 16px;" :style="index2 != 0 ? 'margin-left: 16px;' : ''" class="selectinput_item">
            <el-option v-for="item3 in item2.option_list" :key="item3.value" :label="item3.label"
              :value="item3.value" />
          </el-select>
          <template v-if="showinput(item2) == 'input' || showinput(item2) == 'select'">
            <app-filter-input class="selectinput_item" style="width: 120px; height: 28px; margin-bottom: 16px;margin-left: 16px;" :inputdata="getinput(item2)"
              :data="item2" />
          </template>
        </template>
      </div>
    </div>
  </el-collapse-item>
</template>

<script setup>
const props = defineProps({
  data: Object,
})

const collapselistStyle = (index, arr) => {
  let length = arr.length
  let str = ''
//   if (index == 0) {
//     str += 'padding-right: 8px;'
//   } else if (index == 1) {
//     str += 'border-left: 1px solid #ebebeb;'
//     str += 'padding-right: 8px;'
//     str += 'padding-left: 8px;'
//   } else {
//     str += 'border-left: 1px solid #ebebeb;'
//     str += 'padding-left: 8px;'
//   }
  return str
}

const showinput = row => {
  let show = ''
  row.option_list.forEach(item => {
    if (row.choose == item.value && item.type != null) {
      show = item.type
    }
  })
  return show
}

const getinput = row => {
  let data = {}
  row.option_list.forEach(item => {
    if (row.choose == item.value && item.type != null) {
      data = item
    }
  })
  return data
}

const changechoose = (row) => {
  if (row.option_list[0].values != null) {
    row.option_list.forEach(item => {
      if (item.value == row.choose) {
        if (item.type != 'select') {
          row.values = JSON.parse(JSON.stringify(item.values))
        } else {
          row.values = JSON.parse(JSON.stringify([item.values[0]]))
        }
      }
    });
  }

}
</script>

<style lang="scss" scoped>
.icon-ele {
  margin: 0 8px 0 auto;
  //   color: #409eff;
}

.filter_collapse_checked {
  position: absolute;
  display: flex;
  align-items: center;
  left: 0;
}

.filteredit_collapse-item_content {
  margin: 16px 0 0 0;
  display: flex;
  flex-direction: column;
}

.collapse_list {
  display: flex;
  width: 100%;
//   flex-direction: column;
}

::v-deep .collapse_list .selectinput_item:last-child{
  margin-bottom: 0 !important;
}
</style>

<style>
.filteredit_collapse-item .el-select__wrapper {
  min-height: 28px;
  font-size: 12px;
}

.filteredit_collapse-item .el-select__wrapper {
  padding: 4px 8px !important;
}
</style>